package leetcode.动态规划;


public class 买卖股票的最佳时机121 {
    public static int maxProfit(int[] prices) {
        int minPrice = prices[0];
        int max = 0;
        for (int i = 1; i < prices.length; i++) {
            max = Math.max(max,prices[i] - minPrice);
            if(prices[i] < minPrice)
                minPrice = prices[i];
        }
        return max;

    }


    public static void main(String[] args) {
        int[] prices = {7,1,5,3,6,4};
        int res = maxProfit(prices);
        System.out.println(res);
    }

}
